package com.gombe.credit.app.ui.adapter

import androidx.recyclerview.widget.RecyclerView
import com.gombe.credit.app.R
import com.gombe.credit.lib.adapter.GombeCreditRecyclerViewAdapter
import com.gombe.credit.lib.adapter.GombeCreditViewHolderHelper
import com.gombe.credit.lib.shapeview.layout.GombeCreditLinearLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/3 17:49
 * @Annotation：首页Tab适配器
 */
class AdapterGombeCreditMainTab(recyclerView: RecyclerView?) : GombeCreditRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.act_gombe_credit_main_item) {
    override fun setItemChildListener(helper: GombeCreditViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.tabItemLayout)
    }
    override fun fillData(helper: GombeCreditViewHolderHelper, position: Int, model: JSONObject) {
        val mainTabImageView = helper.getImageView(R.id.mainTabImageView)
        val txtMainTabTitle = helper.getTextView(R.id.txtMainTabTitle)
        txtMainTabTitle.text = model.optString("tabTitle")

        val tabItemLayout = helper.getView<GombeCreditLinearLayout>(R.id.tabItemLayout)
        when(model.optBoolean("isSelect", false)){
            true -> {
                txtMainTabTitle.setTextColor(getColor(R.color.gombe_credit_ff1d1e20))
                mainTabImageView.setImageResource(model.optInt("tabSelectedIcon"))
                tabItemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.theme))
                    .intoBackground()
            }
            else -> {
                txtMainTabTitle.setTextColor(getColor(R.color.gombe_credit_ffc8c8c8))
                mainTabImageView.setImageResource(model.optInt("tabNormalIcon"))
                tabItemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.transparent))
                    .intoBackground()
            }
        }
    }
}